//
//  CommentListViewController.swift
//  app4crew
//
//  Created by apple on 16/3/28.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class CommentListViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
    
    @IBOutlet weak var commentTableView: UITableView!
    
    @IBAction func backbtnclick(sender: AnyObject) {
        Common.commentVC.view.removeFromSuperview()
        backAction()
        Common.rootViewController.mainTabBarController.selectedIndex = 0
    }

    @IBAction func commentbtnclick(sender: AnyObject) {
        let stb:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let tdl:CommentViewController = stb.instantiateViewControllerWithIdentifier("CommentView") as! CommentViewController
        self.presentViewController(tdl, animated: true, completion: nil)
        
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        commentTableView.delegate = self
        navigationItem.leftBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: .Stop, target: self, action: Selector("backAction"))
        navigationItem.rightBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: .Search, target: self, action: nil)
        
        // 自定义返回按钮
//        let backButton = UIBarButtonItem(title: "く返回", style: UIBarButtonItemStyle.Plain, target: self, action: "goBack")
//        
//        self.navigationController?.navigationItem.leftBarButtonItem = backButton
//        self.navigationItem.leftBarButtonItem = backButton
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    //delegate
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell:CommentCellTableViewCell = tableView.dequeueReusableCellWithIdentifier("mycell") as! CommentCellTableViewCell
        cell.commentRating.isIndicator = true
        cell.commentRating.rating = 3
        return cell
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 4
    }
    
    
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        
        self.view.endEditing(true)
    }

    
    // private method
    
    func backAction(){
        if navigationController?.viewControllers.count>1 {
            self.navigationController?.popViewControllerAnimated(true)
        } else {
            self.dismissViewControllerAnimated(true, completion: nil)
        }
    }
    
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
